<template>
  <el-form :model="form" ref="formRef" :rules="rules" label-position="left" label-width="100px" size="medium"
    @submit.prevent>
    <el-form-item prop="chkState" class="required" label-width="auto">
      <el-radio-group v-model="form.chkState">
        <el-radio v-for="(item, index) in chkStateOptions" :key="index" :label="item.value" :disabled="item.disabled"
          style="{display: inline}">{{item.label}}</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item prop="chkRemarks" class="required" label-width="auto">
      <el-input v-model="form.chkRemarks" type="textarea" clearable placeholder="请输入审核意见"></el-input>
    </el-form-item>
  </el-form>
  <el-row type="flex" justify="center">
    <el-button @click="onClose">取消</el-button>
    <el-button type="primary" @click="submitForm">确定</el-button>
  </el-row>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
import { ElMessage } from 'element-plus'
import {
  defineComponent,
  toRefs,
  reactive,
  ref
}
  from 'vue'
export default defineComponent({
  components: {},
  props: {
  },
  setup (props, { emit }) {
    const state = reactive({
      form: {
        chkState: true,
        chkRemarks: ''
      },
      rules: {
        chkState: [{
          required: true,
          message: '字段值不可为空'
        }],
        chkRemarks: [{
          required: true,
          message: '字段值不可为空'
        }]
      },
      chkStateOptions: [{
        label: '通过',
        value: 1
      }, {
        label: '拒绝',
        value: 2
      }]
    })
    const formRef = ref()
    const submitForm = () => {
      formRef.value.validate(async valid => {
        if (!valid) return
        // TODO: 提交表单
        // 发送请求
        console.log(state.form)
        await choiceCheck(state.form)
        // 提示成功
        ElMessage.success('操作成功')
        // 刷新列表
        emit('success')
        // 关闭对话框
        onClose()
      })
    }
    const resetForm = () => {
      formRef.value.resetFields()
    }
    const onClose = () => {
      resetForm()
      emit('close')
    }
    return {
      ...toRefs(state),
      formRef,
      submitForm,
      resetForm,
      onClose
    }
  }
})

</script>
<style></style>
